package com.software.aperture.service;

import com.software.aperture.bean.User;
import com.software.aperture.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {

    @Autowired
    UserRepository userRepository;

    public User loadUserByUsername(String username) throws Exception {
        User user = userRepository.findByAccountName(username);
        if (user == null) {
            throw new Exception("用户名不存在");
        }

        System.out.println("username:" + user.getAccountName() + ";password:" + user.getPassword());
        return user;
    }

    public User findUserByAccountName(String username) {
        return userRepository.findByAccountName(username);
    }

    public void addUser(User user) {
        //user.setPassword(new BCryptPasswordEncoder().encode(user.getPassword()));
        userRepository.save(user);
    }

    public void editUser(User user){
        userRepository.save(user);
    }


}
